package com.magenta.maxoptra.gis.utils;

import com.magenta.maxoptra.gis.GeoRoute;
import com.magenta.maxoptra.gis.GeoStatusCode;
import com.magenta.maxoptra.gis.GeographicCoordinates;

/**
 * Created with IntelliJ IDEA.
 * User: kuznetsovd
 * Date: 05.12.12
 * Time: 13:24
 * To change this template use File | Settings | File Templates.
 */
public class GetRouteProfiler extends AbstractGisProfiler {

    protected GeographicCoordinates from;
    protected GeographicCoordinates to;

    public GetRouteProfiler(String provider, String accountGlobalId, boolean enableProfiling, GeographicCoordinates from, GeographicCoordinates to) {
        super(provider, accountGlobalId, enableProfiling);
        this.from = from;
        this.to = to;
    }

    public String getInitialInfo() {
        return provider + separator + accountGlobalId + separator +
                coordFormat.format(from.getLatitude()) + separator +
                coordFormat.format(from.getLongitude()) + separator +
                coordFormat.format(to.getLatitude()) + separator +
                coordFormat.format(to.getLongitude());
    }

    public void logDuration(GeoRoute route) {
        if (route != null) {
            if (route.getDistanceInKM() >= 0) {
                logDuration(distanceFormat.format(route.getDistanceInKM()) + " km" + separator + distanceFormat.format(route.getDurationInMinutes()) + " min");
            } else {
                GeoStatusCode statusCode = GeoStatusCode.getStatusCode((int) Math.round(route.getDistanceInKM()));
                if (statusCode != null) {
                    logError("error:" + statusCode.getDescription());
                } else {
                    logError("error:" + route.getDistanceInKM());
                }
            }
        }
    }

}
